package dominia.game;


/**
 * A class to represent 2-dimensional game maps.
 * 
 * A game map consists of a 2-dimensional array split into tiles.
 * 
 * @author jfb
 *
 */
public class Map {
	private String		name;

	private int		xSize = 0;
	private int		ySize = 0;

	private Tile[][]	tiles;

	public Map()
	{

	}

	/**
	 * Set the size of the map to the
	 * 
	 * @param x number of tiles in depth
	 * @param y number of tiles in width
	 */
	public void setSize(int x, int y)
	{
		Tile[][] newmap = new Tile[x][y];

		/* copy as much of the old map as possible in the new one */
		for (int i = 0; i < (Math.min(this.xSize, x)); i++)
			for (int j = 0; j < (Math.min(this.ySize, y)); j++)
				newmap[i][j] = this.tiles[i][j];

		this.tiles = newmap;
		this.xSize = x;
		this.ySize = y;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public String getName()
	{
		return this.name;
	}

	public void setTile(int x, int y, Tile tile)
	{
		if ((xSize <= x) || (ySize <= y)) {
			/* throw new Exception() */
		}

		this.tiles[x][y] = tile;
	}

	public Tile getTile(int x, int y)
	{
		return this.tiles[x][y];
	}
}